package cn.jett.domain.strategy.repository;

import cn.jett.domain.strategy.model.entity.StrategyAwardEntity;
import cn.jett.domain.strategy.model.entity.StrategyEntity;
import cn.jett.domain.strategy.model.entity.StrategyRuleEntity;
import cn.jett.domain.strategy.model.valobj.RuleTreeVO;
import cn.jett.domain.strategy.model.valobj.StrategyAwardStockKeyVO;
import cn.jett.domain.strategy.model.vo.StrategyAwardRuleModelVO;
import cn.jett.types.common.Constants;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author 战斗天使
 * @Description 策略仓储接口
 * @Date 2024/6/14
 */
public interface IStrategyRepository {
    /**
     * 根据策略id查询奖品集合（包括奖品id、策略id、奖品概率、奖品库存）
     * @param strategyId
     * @return
     */
    List<StrategyAwardEntity> queryStrategyAwardList(Long strategyId);
    /**
     * 存储策略范围值和概率查找表
     * @param key
     * @param rateRange
     * @param shuffleStrategyAwardSearchRateTables
     */
    void storeStrategyAwardSearchRateTables(String key, int rateRange, HashMap<Integer, Integer> shuffleStrategyAwardSearchRateTables);
    /**
     * 根据策略id查找概率范围
     * @param strategyId
     * @return
     */
    int getRateRange(Long strategyId);

    /**
     * 根据策略id和权重值查找概率范围
     * @param key
     * @return
     */
    int getRateRange(String key);

    /**
     * 根据随机值返回奖品
     * @param key
     * @param rateKey
     * @return
     */
    Integer getStrategyAwardAssemble(String key, int rateKey);

    /**
     * 查询策略规则
     * @param strategyId
     * @return
     */
    StrategyEntity queryStrategyEntityByStrategyId(Long strategyId);

    /**
     * 根据策略id和规则权重查询规则实体
     * @param strategyId
     * @param ruleModel
     * @return
     */
    StrategyRuleEntity queryStrategyRule(Long strategyId, String ruleModel);

    /**
     * 查询策略权重值
     * @param strategyId
     * @param awardId
     * @param ruleModel
     * @return
     */
    String queryStrategyRuleValue(Long strategyId, Integer awardId, String ruleModel);

    /**
     * 根据策略id和奖品id查询策略
     * @param strategyId
     * @param awardId
     * @return
     */
    StrategyAwardRuleModelVO queryStrategyAwardRuleModelVO(Long strategyId, Integer awardId);

    /**
     * 查询策略权重值
     * @param strategyId
     * @param ruleModel
     * @return
     */
    String queryStrategyRuleValue(Long strategyId, String ruleModel);


    RuleTreeVO queryRuleTreeVOByTreeId(String treeId);


    Boolean subtractionAwardStock(String cacheKey);


    void awardStockConsumeSendQueue(StrategyAwardStockKeyVO strategyAwardStockKeyVO);


    StrategyAwardStockKeyVO takeQueueValue() throws InterruptedException;


    void updateStrategyAwardStock(Long strategyId, Integer awardId);

    void cacheStrategyAwardCount(String cacheKey, Integer awardCount);
}
